﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Peojct2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet1.userInfo”中。您可以根据需要移动或删除它。
            //this.userInfoTableAdapter.Fill(this.dataSet1.userInfo);

            //查询代码
            var peojct = "SELECT * FROM Students  ";

            var dt = Casing.GetDataTable(peojct);
                       
            
            dataGridView1.DataSource = dt; //把数据语言绑定到这里去

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;  //在窗口点击编辑的代码 
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //参数
            var name = textBox1.Text;
            var sql = string.Format("Select * from Students where StudentName like '%{0}%'", name);
            var dt = Casing.GetDataTable(sql);
            dataGridView1.DataSource = dt;
           
           

        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            

            Peojct peojct = new Peojct();
            peojct.Show();

        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void button3_Click(object sender, EventArgs e)
        {
            /*
             var id = (int)dataGridView1.SelectedRows[0].Cells["Id"].Value;
            var name = (string)dataGridView1.SelectedRows[0].Cells["StudentName"].Value;
            var age = (int)dataGridView1.SelectedRows[0].Cells["StudentAge"].Value;
            var soure = (int)dataGridView1.SelectedRows[0].Cells["StudentSoure"].Value;
            var sex = (string)dataGridView1.SelectedRows[0].Cells["StudentSex"].Value;
            Peojct peojct = new Peojct(id, name, age, soure, sex);
            */
            Peojct peojct = new Peojct();
            peojct.Show();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            Peojct peojct = new Peojct();
            peojct.Show();
        }
    }
    }

